<?php
defined ( 'IN_TS' ) or die ( 'Access Denied.' );

$userid = intval ( $TS_USER ['userid'] );

$strUser = aac('user')->getOneUser($userid);



$planid = intval ( $_POST ['planid'] );

$isRecommend = $new ['plan']->findCount ( 'plan_recommend', array (
		'planid' => $planid,
		'userid' => $userid 
) );

$strPlan = $new ['plan']->find('plan',array(
	'planid'=>$planid,
));

if ($isRecommend > 0) {
	$isRecommend = $new ['plan']->delete ( 'plan_recommend', array (
		'planid' => $planid,
		'userid' => $userid
	) );
	// 对积分进行处理
	aac('user') -> doScore($TS_URL['app'], $TS_URL['ac'], $TS_URL['ts'],$strPlan['userid'],-5);
	aac('user') -> doScore($TS_URL['app'], $TS_URL['ac'], $TS_URL['ts'],$userid,5);

}else{


	if ($strUser['count_score']<5) {
		echo 0;
		exit ();
	}

	$new ['plan']->create ( 'plan_recommend', array (
		'planid' => $planid,
		'userid' => $userid
	) );

	// 对积分进行处理
	aac('user') -> doScore($TS_URL['app'], $TS_URL['ac'], $TS_URL['ts'],$strPlan['userid'],5);
	aac('user') -> doScore($TS_URL['app'], $TS_URL['ac'], $TS_URL['ts'],$userid,-5);

}


$count_recommend = $new ['plan']->findCount ( 'plan_recommend', array (
		'planid' => $planid
) );

$new ['plan']->update ( 'plan', array (
		'planid' => $planid
), array (
		'count_recommend' => $count_recommend 
) );

echo 1;
exit ();